import asyncio
from common.variables import future_symbols, spot_symbols, time_counts, TimeFrameType

# from pytypes import typechecked
from datetime import datetime
from trade.data.add_kline_data import add_batch_klines, watch_ohlcv_data_timely


def main_job():
    timeframe: TimeFrameType = "1m"
    preloads = 300
    ed = datetime.now().isoformat()
    st = datetime.fromtimestamp(
        datetime.now().timestamp() - preloads * time_counts[timeframe]
    ).isoformat()
    add_batch_klines(
        future_symbols + spot_symbols, st, ed, timeframe, n_jobs=6, max_part=100000
    )
    loop = asyncio.get_event_loop()
    task1 = loop.create_task(
        watch_ohlcv_data_timely(future_symbols + spot_symbols, timeframe, to_kafka=True)
    )
    # task2 = loop.create_task(watch_ohlcv_data_timely(spot_symbols, timeframe, to_kafka=True))
    loop.run_until_complete(task1)
    # loop.run_until_complete(task2)


if __name__ == "__main__":
    main_job()
